home *** CD-ROM | disk | FTP | other *** search
/ Champak 109 / Vol 109.iso / games / paper_ma.swf / scripts / frame_18 / DoAction_2.as next >
Text File  |  2008-11-12  |  3KB  |  119 lines

  1. var heroW = 15;
  2. var heroH = 35;
  3. var velY = 0;
  4. var stepS = 6;
  5. var jumpS = 14;
  6. var jumping = true;
  7. this.onEnterFrame = function()
  8. {
  9.    if(Key.isDown(37))
  10.    {
  11.       var _loc3_ = 0;
  12.       while(_loc3_ < stepS)
  13.       {
  14.          _root.hero._x--;
  15.          var _loc2_ = 0;
  16.          while(_loc2_ <= heroH)
  17.          {
  18.             if(_root.ground.hitTest(_root.hero._x - heroW,_root.hero._y - _loc2_,true))
  19.             {
  20.                _loc3_ = stepS;
  21.                _loc2_ = heroH + 1;
  22.                _root.hero._x = _root.hero._x + 1;
  23.             }
  24.             _loc2_ = _loc2_ + 1;
  25.          }
  26.          _loc3_ = _loc3_ + 1;
  27.       }
  28.    }
  29.    else if(Key.isDown(39))
  30.    {
  31.       _loc3_ = 0;
  32.       while(_loc3_ < stepS)
  33.       {
  34.          _root.hero._x = _root.hero._x + 1;
  35.          _loc2_ = 0;
  36.          while(_loc2_ <= heroH)
  37.          {
  38.             if(_root.ground.hitTest(_root.hero._x + heroW,_root.hero._y - _loc2_,true))
  39.             {
  40.                _loc3_ = stepS;
  41.                _loc2_ = heroH + 1;
  42.                _root.hero._x--;
  43.             }
  44.             _loc2_ = _loc2_ + 1;
  45.          }
  46.          _loc3_ = _loc3_ + 1;
  47.       }
  48.    }
  49.    if(Key.isDown(38) && !jumping)
  50.    {
  51.       velY = jumpS;
  52.       jumping = true;
  53.    }
  54.    if(jumping)
  55.    {
  56.       if(velY > 0)
  57.       {
  58.          _loc2_ = 0;
  59.          while(_loc2_ < velY)
  60.          {
  61.             _root.hero._y--;
  62.             _loc3_ = - heroW;
  63.             while(_loc3_ <= heroW)
  64.             {
  65.                if(_root.ground.hitTest(_root.hero._x + _loc3_,_root.hero._y - heroH,true))
  66.                {
  67.                   _loc2_ = velY;
  68.                   _loc3_ = heroW + 1;
  69.                   _root.hero._y = _root.hero._y + 1;
  70.                   velY = 0;
  71.                }
  72.                _loc3_ = _loc3_ + 1;
  73.             }
  74.             _loc2_ = _loc2_ + 1;
  75.          }
  76.       }
  77.       else
  78.       {
  79.          _loc2_ = 0;
  80.          while(_loc2_ > velY)
  81.          {
  82.             _root.hero._y = _root.hero._y + 1;
  83.             _loc3_ = - heroW;
  84.             while(_loc3_ <= heroW)
  85.             {
  86.                if(_root.ground.hitTest(_root.hero._x + _loc3_,_root.hero._y,true))
  87.                {
  88.                   _loc2_ = velY;
  89.                   _loc3_ = heroW + 1;
  90.                   _root.hero._y--;
  91.                   velY = 0;
  92.                   jumping = false;
  93.                }
  94.                _loc3_ = _loc3_ + 1;
  95.             }
  96.             _loc2_ = _loc2_ - 1;
  97.          }
  98.       }
  99.       velY--;
  100.    }
  101.    else if(!jumping)
  102.    {
  103.       _loc3_ = - heroW;
  104.       while(_loc3_ <= heroW)
  105.       {
  106.          if(_root.ground.hitTest(_root.hero._x,_root.hero._y + 1,true))
  107.          {
  108.             break;
  109.          }
  110.          if(_loc3_ == heroW)
  111.          {
  112.             velY = 0;
  113.             jumping = true;
  114.          }
  115.          _loc3_ = _loc3_ + 1;
  116.       }
  117.    }
  118. };
  119.